package com.team.service.impl;

import com.team.dao.DiseaseMapper;
import com.team.dao.ReservationMapper;
import com.team.entity.Disease;
import com.team.entity.Reservation;
import com.team.service.DiseaseService;
import com.team.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author : 陈灰灰
 * @Date: 2022/10/16/20:56
 * @Description:
 */
@Service
public class DiseaseServiceImpl implements DiseaseService {
    @Autowired
    private DiseaseMapper diseaseMapper;
    @Autowired
    private ReservationMapper reservationMapper;

    /**@author:chh
     * 查询疾病通过预订id
     * @param id id
     * @return {@link Result}
     */
    @Override
    public Result queryDiseaseByReservationId(Integer id) {
        Disease disease = diseaseMapper.selectByPrimaryKey(id);
        return new Result(200,"查询成功",disease);
    }

    /**@author：chh
     * 增加病例
     * @param disease 疾病
     * @return {@link Result}
     */
    @Override
    public Result addDisease(Disease disease) {
        int i = diseaseMapper.insertSelective(disease);
        Reservation reservation = new Reservation();
        reservation.setId(disease.getReservationId());
        reservation.setIsvisit(disease.getStatus());
        reservationMapper.updateByPrimaryKeySelective(reservation);
        return new Result(200,"添加成功");
    }

    /**@author：chh
     * 选择通过预订id
     * @param id id
     * @return {@link Result}
     */
    @Override
    public Result selectByReservationId(int id) {
        Disease disease = diseaseMapper.selectByReservationId(id);
        if(disease!=null){
            return new Result(200,"查询成功",disease);
        }else{
            return new Result(500,"查询失败",disease);
        }

    }
}
